﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CIIS.Common;
using Contract.Domain;
using DevExpress.XtraLayout.Utils;
using Framework.Domain;
using DevExpress.XtraEditors;

namespace CIIS
{
    public partial class SecretPerson : BaseForm
    {
        public SecretPerson()
        {
            InitializeComponent();

            DevControlUtils.Instance.InitLookUpEdit(lookUpEditActiveClass, dao.GetDropdownControlParam<bm_tq_hdzcfl>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditAreaClass, dao.GetDropdownControlParam<bm_tq_lyfl>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditCountry, dao.GetDropdownControlParam<bm_tq_gj>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditEdu, dao.GetDropdownControlParam<bm_tq_whcd>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditFunctionType, dao.GetDropdownControlParam<bm_tq_gnlb>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditJob, dao.GetDropdownControlParam<bm_tq_zy>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditNature, dao.GetDropdownControlParam<bm_tq_mz>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditPrevType, dao.GetDropdownControlParam<bm_tq_qklx>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditSex, dao.GetDropdownControlParam<bm_tq_xb>());
            DevControlUtils.Instance.InitLookUpEdit(lookUpEditUsageClass, dao.GetDropdownControlParam<bm_shzt>());

            if (OptType != EOperateType.Change)
            {
                layoutControlItemNextStep.Visibility = LayoutVisibility.Never;
                emptySpaceItemNextStep.Visibility = LayoutVisibility.Never;
            }

            buttonSave.Click += new EventHandler(buttonSave_Click);
            buttonPrint.Click += new EventHandler(buttonPrint_Click);
            buttonBack.Click += new EventHandler(buttonBack_Click);
            buttonNextStep.Click += new EventHandler(buttonNextStep_Click);

            buttonSave.DialogResult = DialogResult.OK;
        }

        void buttonNextStep_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        void buttonBack_Click(object sender, EventArgs e)
        {
            Close();
        }

        void buttonPrint_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (OptType == EOperateType.Add)
                {
                    BindEntity.State.New = true;
                }
                t_tq_tqry o = dao.Dao.SaveOrUpdate(BindEntity) as t_tq_tqry;
                XtraMessageBox.Show("保存成功");
            }
            catch
            {
                XtraMessageBox.Show("保存失败");
            }
            finally
            {
                Close();
            }
        }

        /// <summary>
        /// 绑定数据源，在show窗口之前需要调用
        /// </summary>
        /// <param name="tqry"></param>
        public override void BindData(Entity entity)
        {
            t_tq_tqry a = new t_tq_tqry();
            BindEntity = entity as t_tq_tqry;
            if (BindEntity == null)
            {
                BindEntity = new t_tq_tqry();
            }
            if (BindEntity != null)
            {
                textEditAddr.DataBindings.Add("Text", BindEntity, "HKSZD");
                textEditAddrDetail.DataBindings.Add("Text", BindEntity, "HKSZDXZ");
                textEditBirthAddr.DataBindings.Add("Text", BindEntity, "JG");
                textEditComAddr.DataBindings.Add("Text", BindEntity, "LLDZ");
                textEditCurrentAddr.DataBindings.Add("Text", BindEntity, "XZZ");
                textEditCurrentAddrDetail.DataBindings.Add("Text", BindEntity, "XZZXZ");
                textEditName.DataBindings.Add("Text", BindEntity, "XM");
                textEditNickName.DataBindings.Add("Text", BindEntity, "BM");
                textEditNo.DataBindings.Add("Text", BindEntity, "Id");
                textEditPosName.DataBindings.Add("Text", BindEntity, "ZKDMC");
                textEditTel.DataBindings.Add("Text", BindEntity, "LXDH");
                textEditWorkAddr.DataBindings.Add("Text", BindEntity, "GZDW");

                lookUpEditActiveClass.DataBindings.Add("EditValue", BindEntity, "ZCCDFL");
                lookUpEditAreaClass.DataBindings.Add("EditValue", BindEntity, "LYFL");
                lookUpEditCountry.DataBindings.Add("EditValue", BindEntity, "GJ");
                lookUpEditEdu.DataBindings.Add("EditValue", BindEntity, "WHCD");
                lookUpEditFunctionType.DataBindings.Add("EditValue", BindEntity, "GNLB");
                lookUpEditJob.DataBindings.Add("EditValue", BindEntity, "GZDW");
                lookUpEditNature.DataBindings.Add("EditValue", BindEntity, "MZ");
                lookUpEditPrevType.DataBindings.Add("EditValue", BindEntity, "QKLX");
                lookUpEditSex.DataBindings.Add("EditValue", BindEntity, "XB");
                lookUpEditUsageClass.DataBindings.Add("EditValue", BindEntity, "ZYDXFL");

                memoEditExpression.DataBindings.Add("Text",BindEntity,"BXQK");
                memoEditPrevInfo.DataBindings.Add("Text",BindEntity,"QKQK");
                memoEditRemark.DataBindings.Add("Text",BindEntity,"BZ");
                memoEditResume.DataBindings.Add("Text",BindEntity,"GRJL");
            }
        }
    }
}
